package dt.member;


import java.io.IOException;
import java.io.Reader;
import java.util.Map;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class memberModifyAction extends ActionSupport {
	
	public static Reader reader;
	public static SqlMapClient sqlMapper;
	
	private memberVO paramClass; //�Ķ���͸� ������ ��ü
	private memberVO resultClass; //���� ��� ���� ������ ��ü
	private int updateCheck;
	
	
	private String passwd;;
	private String nickname;
	private String name;
	private String email;
	private String mobile1;
	private String mobile2;
	private String mobile3;
	private String phone1;
	private String phone2;
	private String phone3;
	private String zip;
	private String addr1;
	private String addr2;
	
	//����
	public memberModifyAction() throws IOException {
		reader = Resources.getResourceAsReader("sqlMapConfig.xml"); //sqlMapConfig.xml ������ ���������� �����´�.
		sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader); //sqlMapConfig.xml ������ ����� sqlMapper ��ü ��
		reader.close();
	}
	
	//�Խñ� ����
	public String execute() throws Exception {
		
		//�Ķ���Ϳ� ����Ʈ ��ü ��
		paramClass = new memberVO();
		resultClass = new memberVO();
		
		ActionContext context=ActionContext.getContext();
		Map<String,Object> session = context.getSession();
		//�̸� ������ �ٿ��, �ش� ������ id���� ������ memberVO�� DB�� �ڷḦ ������
		if(session.size()>0) {
			String id = (String)session.get("id");
			resultClass = (memberVO) sqlMapper.queryForObject("getMember", id);
			paramClass = resultClass;
			
			//������ �׸� ����
			paramClass.setId(id);
			paramClass.setPasswd(getPasswd());
			paramClass.setNickname(getNickname());
			paramClass.setName(getName());
			paramClass.setEmail(getEmail());
			paramClass.setMobile1(getMobile1());
			paramClass.setMobile2(getMobile2());
			paramClass.setMobile3(getMobile3());
			paramClass.setPhone1(getPhone1());
			paramClass.setPhone2(getPhone2());
			paramClass.setPhone3(getPhone3());
			paramClass.setZip(getZip());
			paramClass.setAddr1(getAddr1());
			paramClass.setAddr2(getAddr2());
			
			// �����Ѵ�!
			sqlMapper.update("updateMember", paramClass);
			updateCheck = 1;
			return SUCCESS;
		}
		else {
			updateCheck = -1;
			return INPUT;
		}
	}

	public static Reader getReader() {
		return reader;
	}

	public static void setReader(Reader reader) {
		memberModifyAction.reader = reader;
	}

	public static SqlMapClient getSqlMapper() {
		return sqlMapper;
	}

	public static void setSqlMapper(SqlMapClient sqlMapper) {
		memberModifyAction.sqlMapper = sqlMapper;
	}

	public memberVO getParamClass() {
		return paramClass;
	}

	public void setParamClass(memberVO paramClass) {
		this.paramClass = paramClass;
	}

	public memberVO getResultClass() {
		return resultClass;
	}

	public void setResultClass(memberVO resultClass) {
		this.resultClass = resultClass;
	}

	public String getPasswd() {
		return passwd;
	}

	public void setPasswd(String passwd) {
		this.passwd = passwd;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getMobile1() {
		return mobile1;
	}

	public void setMobile1(String mobile1) {
		this.mobile1 = mobile1;
	}

	public String getMobile2() {
		return mobile2;
	}

	public void setMobile2(String mobile2) {
		this.mobile2 = mobile2;
	}

	public String getMobile3() {
		return mobile3;
	}

	public void setMobile3(String mobile3) {
		this.mobile3 = mobile3;
	}

	public String getPhone1() {
		return phone1;
	}

	public void setPhone1(String phone1) {
		this.phone1 = phone1;
	}

	public String getPhone2() {
		return phone2;
	}

	public void setPhone2(String phone2) {
		this.phone2 = phone2;
	}

	public String getPhone3() {
		return phone3;
	}

	public void setPhone3(String phone3) {
		this.phone3 = phone3;
	}

	public String getZip() {
		return zip;
	}

	public void setZip(String zip) {
		this.zip = zip;
	}

	public String getAddr1() {
		return addr1;
	}

	public void setAddr1(String addr1) {
		this.addr1 = addr1;
	}

	public String getAddr2() {
		return addr2;
	}

	public void setAddr2(String addr2) {
		this.addr2 = addr2;
	}

	public int getUpdateCheck() {
		return updateCheck;
	}

	public void setUpdateCheck(int updateCheck) {
		this.updateCheck = updateCheck;
	}

}
